package com.xbongbong.paas.enums;


import com.xbongbong.i18n.util.I18nMessageUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 统计方式
 * @author 梁鲁江
 * @version v1.0
 * @date 2019/1/22 20:21
 * @since v1.0
 */
public enum AddressEnum {
    /**
     * 地址的省份
     */
    PROVINCE(1,"province", "enum.address.name.province"),
    /**
     * 地址的市
     */
    CITY(2,"city", "enum.address.name.city"),
    /**
     * 地址的地区
     */
    DISTRICT(3,"district", "enum.address.name.district"),
    /**
     * 详细地址
     */
    ADDRESS(4,"address", "enum.address.name.address"),
            ;

    public int code;
    public String alias;
    public String name;

    AddressEnum(Integer code,String alias,String name){
        this.code = code;
        this.alias = alias;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getAlias() {
        return alias;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static List<AddressEnum> getAllEnum(){
        List<AddressEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static AddressEnum getByAlias(String alias) {
        if(alias != null){
            for (AddressEnum cacheCode : values()) {
                if (Objects.equals(cacheCode.getAlias(), alias)) {
                    return cacheCode;
                }
            }
        }
        return null;
    }

    public static List<String> getAliasList() {
        List<String> alias = new ArrayList<>();
        for (AddressEnum cacheCode : values()) {
            alias.add(cacheCode.getAlias());
        }
        return alias;
    }
}
